/**
 * Created by zhuyongjie on 2017/12/13.
 */
$(function(){
    setAjaxLoading();

    var row = getGlobalVariable("taskConfigRow");
    var rowJson = null;
    if(row.isJSON()){
        rowJson = JSON.parse(row);
    }

    if(rowJson){
        if(type == "add"){
            var processKey = rowJson.key;
            $("#processKey").textbox('setValue',processKey);
        }else if(type == "edit"){
            $.each(rowJson,function (key, value) {
                $("#" + key).textbox('setValue',value);
            })
        }

    }

});

/**
 * 选择参与者
 */
function choseRole() {
    var showRoleUrl = path +"/flow/showRolePage";
    top.layer.open({
        type: 2,
        id: "taskConfig" + Math.random(),//不能有固定id，否则多层次弹窗失败
        title: "选择参与者",
        area: ['800px','500px'],
        shadeClose: false,
        shade: 0.3,
        maxmin: true,
        content: showRoleUrl ,
        zIndex: top.layer.zIndex,//重点1,
        success: function (layero) {
            top.layer.setTop(layero); //重点2
        },
        end: function () {
           var selectedRole = getGlobalVariable("selectedRole");
           var selectedRoleName =  getGlobalVariable("selectedRoleName");
           if(selectedRole != null && selectedRole != ''){
               $("#candidatName").textbox('setValue',selectedRoleName);
               $("#candidat").textbox('setValue',selectedRole);
           }
        },
        cancel: function (index) {
            top.layer.close(index);
        }
    });
}

/**
 * 提交表单
 */
function saveData() {
    if (!validform("taskConfigForm")) {
        return false;
    }
    $("#taskConfigForm").ajaxSubmit({
        type : "POST",
        url :path + '/flow/saveFlowTaskConf/' + type,
        dataType : "json",
        data:{},
        success : function callback(data) {
            var analyMsg = data;
            if (analyMsg.code != '0000') {
                $.alert('default', 'info', analyMsg.msg);
            } else {
                $.alert('default', 'info', "保存成功");
                setTimeout("closeLayer()",100);//设置延时，防止IE下出现异常
            }
        },
        error : function(data, textstatus) {
            $.alert('default', 'error', analyMsg.msg);
        }
    });
}